package com.venusj.juc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author venusj
 * @date 2021/3/18
 */
public class ObjectWaitAndNotifyTest {

    static Object objectLock = new Object();

    static Lock lock = new ReentrantLock();

    public static void main(String[] args) {
        objectWaitAndNotify();
    }

    private static void objectWaitAndNotify() {
        new Thread(() -> {

            synchronized (objectLock) {
                System.out.println("进入");
                try {
                    objectLock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "------------" + "被唤醒");
            }

        }, "A").start();


        new Thread(() -> {
            synchronized (objectLock) {
                objectLock.notify();
                System.out.println(Thread.currentThread().getName()+ "通知--------------");
            }
        }, "B").start();
    }
}
